/*
 * Copyright 2025 The JA-SIG Collaborative. All rights reserved.
 * distributed with this file and available online at
 */
package com.lap.auth.adapter.driving.query.module.repository;

import com.lap.auth.adapter.driving.query.module.ModuleQueryConverter;
import com.lap.auth.adapter.driving.query.module.mapper.ModuleQueryMapper;
import com.lap.auth.adapter.driving.query.module.po.ModuleQueryPo;
import com.lap.auth.application.module.dto.ModuleDto;
import com.lap.auth.application.module.dto.QueryModulePageQuery;
import com.lap.auth.application.module.repository.ModuleQueryRepository;
import com.lap.framework.common.dto.page.PageResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@RequiredArgsConstructor
@Repository
public class ModuleQueryRepositoryImpl implements ModuleQueryRepository {

  private final ModuleQueryConverter moduleQueryConverter;
  private final ModuleQueryMapper moduleQueryMapper;

  @Override
  public PageResponse<ModuleDto> findByConditionPaged(QueryModulePageQuery query) {
    long count = moduleQueryMapper.countPageByCondition(query);
    if (count == 0L) {
      return PageResponse.ok(count);
    }
    List<ModuleQueryPo> list = moduleQueryMapper.selectPageByCondition(query);
    return PageResponse.ok(moduleQueryConverter.toDtoList(list), count);
  }
}
